package com.wondersgroup.fjzlpt.console.utils;

import com.alibaba.fastjson.JSONObject;
import com.quick.framework.boot.web.utils.RequestUtils;
import com.quick.framework.boot.web.wapper.QuickPrincipal;
import com.quick.framework.util.QuickPrincipalUtils;
import com.wondersgroup.fjzlpt.console.constant.SystemConstant;
import org.apache.commons.lang.StringUtils;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 访问层的工具类
 */
public class ControllerCommonUtils extends SystemConstant{

    public static JSONObject getRequestData(HttpServletRequest request){
        JSONObject requestData = new JSONObject(1);
		/*是否是管理者*/
        boolean isManager = true;
        QuickPrincipal principal = (QuickPrincipal)request.getUserPrincipal();
        String WSJGLBDM = principal.getUserInfo().getString("WSJGLBDM");
        if(!StringUtils.isEmpty(WSJGLBDM) && WSJGLBDM.indexOf(WSGLJGLBDM) != 0){
            isManager = false;
            JSONObject userInfo = principal.getUserInfo();
            requestData.put("PTJGID", userInfo.getString("PTJGID"));
            requestData.put("YLJGDM", userInfo.getString("YLJGDM"));
            requestData.put("YLJGMC", userInfo.getString("YLJGMC"));
        }
        requestData.put("isManager", isManager);
        return requestData;
    }

    public static Map getUserQqueryPower(HttpServletRequest request){
        Map<String, String> map = RequestUtils.GetParameterMap(request);
        QuickPrincipal principal = (QuickPrincipal)request.getUserPrincipal();
        JSONObject userInfo = principal.getUserInfo();
		/*获取当前用户的卫生机构管理类别*/
        String WSJGLBDM = userInfo.getString("WSJGLBDM");
        if(WSJGLBDM.indexOf(WSGLJGLBDM) == 0){
			/*如果属于管理机构 则按照行政区划查询*/
            String JGXZQHDM = principal.getUserInfo().getString("JGXZQHDM");
            map.put("JGXZQHDM", JGXZQHDM);
            map.put("ROLETYPE" , "");
        }else{
            String ptjgid = QuickPrincipalUtils.getPtjgID(request);
            map.put("PTJGID",ptjgid);
            map.put("ROLETYPE" , "2");
        }
        return map;
    }
}
